package svc

import (
	"api/internal/config"
	"api/internal/middleware"
	"cart_srv/carlclient"
	"github.com/zeromicro/go-zero/rest"
	"github.com/zeromicro/go-zero/zrpc"
	"goods_srv/goodsclient"
	"order_srv/orderclient"
	"user_srv/userclient"
)

type ServiceContext struct {
	Config    config.Config
	AuthToken rest.Middleware
	UserSrv   userclient.User
	CarlSrv   carlclient.Carl
	GoodsSrv  goodsclient.Goods
	OrderSrv  orderclient.Order
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:    c,
		AuthToken: middleware.NewAuthTokenMiddleware().Handle,
		UserSrv:   userclient.NewUser(zrpc.MustNewClient(c.UserSrv)),
		CarlSrv:   carlclient.NewCarl(zrpc.MustNewClient(c.CarlSrv)),
		GoodsSrv:  goodsclient.NewGoods(zrpc.MustNewClient(c.GoodsSrv)),
		OrderSrv:  orderclient.NewOrder(zrpc.MustNewClient(c.OrderSrv)),
	}
}
